package com.heima.admin.job;

import com.heima.admin.service.WemediaNewsAutoScanService;
import com.heima.feigns.wemedia.WemediaFeign;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Slf4j
public class WeMediaNewsAutoScanJob {

    @Autowired
    WemediaFeign wemediaFeign;

    @Autowired
    WemediaNewsAutoScanService wemediaNewsAutoScanService;


    @XxlJob("wemediaAutoScanJob")
    public ReturnT wemediaAutoScanJob(String params){
        log.info("定时发布文章任务被触发");
        //远程调用wemedia 查询待发布的文章
        List<Integer> idList = wemediaFeign.findRelease();

        if (idList!=null&&idList.size()>0){
        //调用自动发布方法   发布文章
            idList.forEach(wemediaNewsAutoScanService::autoScanByMediaNewsId);//入参和方法调用的参数一致时,可以使用方法引用
        }


        return ReturnT.SUCCESS;
    }
}
